package com.diandi.activity.config.shiro;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Created by 袁恩光 on 2018/3/22.
 */
@Component
@ConfigurationProperties("shiro")
public class ShiroProperties {

    /**
     * 过滤默认按照,分割
     */
    private static final String SPLIT_DOT = ",";

    private Map<String, String> filter = new LinkedHashMap<>();

    public Map<String, String> getFilter() {
        return filter;
    }
    public Map<String, String> getShiroFilter() {
        Map<String, String> map = new LinkedHashMap<>();
        for (String key : this.filter.keySet()) {
            if (null != filter.get(key) && !"".equals(filter.get(key))) {
                String[] values = filter.get(key).split(SPLIT_DOT);
                for (String value : values) {
                    map.put(value, key);
                }
            }
        }
        return map;
    }

    public void setFilter(Map<String, String> filter) {
        this.filter = filter;
    }
}
